package io.zsy.annotation.aop.anno;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @author zhangshuaiyin
 * @date 2022/4/25 21:01
 */
@Aspect
@Component
public class UserProxy {

    @Pointcut(value = "execution(* io.zsy.annotation.aop.anno.User.add(..))")
    public void pointCut() {
    }

    @Before("pointCut()")
    public void before() {
        System.out.println("UserProxy before - 前置通知");
    }

    @After("execution(* io.zsy.annotation.aop.anno.User.add(..))")
    public void after() {
        System.out.println("UserProxy after - 后置通知");
    }

    @Around("execution(* io.zsy.annotation.aop.anno.User.add(..))")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("UserProxy around - 环绕通知 方法执行前");
        Object result = joinPoint.proceed();
        System.out.println("UserProxy around - 环绕通知 方法执行后");
        return result;
    }

    @AfterThrowing("execution(* io.zsy.annotation.aop.anno.User.add(..))")
    public void afterThrowing() {
        System.out.println("UserProxy afterThrowing - 异常通知");
    }

    @AfterReturning("execution(* io.zsy.annotation.aop.anno.User.add(..))")
    public void afterReturning() {
        System.out.println("UserProxy afterReturning - 最终通知");
    }
}
